package com.zxj.camerademo.utils;

import android.os.Environment;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;

public class FileUtil {

    private static  String rootFolderPath = Environment.getExternalStorageDirectory() + File.separator + "CameraDemo";
    public static File createImageFile(boolean isCrop){
        File rootFile = new File(rootFolderPath + File.separator + "capture");
        if(!rootFile.exists()){
            rootFile.mkdirs();
        }
        String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
        String fileName;
        if(isCrop){
            fileName = "IMG_"+timeStamp+"_CROP.jpg";
        }else {
            fileName = "IMG_"+timeStamp+".jpg";
        }
        return new File(rootFile.getAbsolutePath() + File.separator + fileName);
    }

    public static File  createCameraFile(String folderName){
        File rootFile = new File(rootFolderPath + File.separator + folderName);
        if(!rootFile.exists()){
            rootFile.mkdirs();
        }
        String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
        String fileName = "IMG_"+timeStamp+".jpg";
        return new File(rootFile.getAbsolutePath() + File.separator + fileName);
    }

    public static File createVideoFile(){
        File rootFile = new File(rootFolderPath + File.separator + "video");
        if (!rootFile.exists())
            rootFile.mkdirs();

        String timeStamp =new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
        String fileName = "VIDEO_"+timeStamp+".mp4";
        return new File(rootFile.getAbsolutePath() + File.separator + fileName);
    }
}
